package com.wxy.config;

import jakarta.annotation.PreDestroy;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class ElasticSearchConfig {                              //这种注入方法是最高效，而且符合最佳实践
    private final RestHighLevelClient client;
    @Autowired
    public ElasticSearchConfig(RestHighLevelClient client) {
        this.client = client;
    }
    @PreDestroy
    public void destroy() throws IOException {
        client.close();
    }
}
